<!DOCTYPE html>
<html data-layout-decorate="~{fragment/layout}">
<head>
<meta charset="UTF-8">
<title>添加授课日志</title>
<link rel="stylesheet" th:href="@{../webjars/bootstrap-select/2.0.0-beta1/dist/css/bootstrap-select.css}">
<link data-th-href="@{../webjars/bootstrapvalidator/css/bootstrapValidator.css}"	rel="stylesheet" />
<script type="text/javascript" 	th:src="@{../webjars/bootstrap-select/2.0.0-beta1/dist/js/bootstrap-select.js}"></script>
<script	data-th-src="@{../webjars/bootstrapvalidator/js/bootstrapValidator.js}"></script>
<script data-th-src="@{../webjars/bootbox/4.4.0/bootbox.js}"></script>
<script data-th-src="@{../webjars/bootstrap-table/bootstrap-table.js}"></script>
<script	data-th-src="@{../webjars/bootstrap-table/locale/bootstrap-table-zh-CN.js}"></script>
<script type="text/javascript"data-th-src="@{../static/layDate-v5.0.9/laydate/laydate.js}"></script>
<style type="text/css">
	.input-group{
		margin-bottom: 15px;
	}
</style>
</head>
<body>
<section layout:fragment="content" id="aaa">
<script type="text/javascript">
$(function(){
	$('#kc').selectpicker({				//初始化下拉框
		title:'',
		width:180
	}); 
	
	$("#content").selectpicker({		//初始化下拉框
		title:'',
		width:180
	});
	
	var time = $("#time").val();
	if(time==null){
		$("#tj").prop('disabled', true);
	}

	//获取当前时间
	var date = new Date();   //得到的不是常规格式
	//转为常规格式
	var d = date.toLocaleString();
	//获取当前年
	var year = date.getFullYear();
	//获取当前月
	var month = date.getMonth()+1;
	//获取当前日
	var day = date.getDate();
	//获取当前小时
	var hours = date.getHours();
	//获取当前分钟
	var minutes = date.getMinutes();
	//获取当前秒
	var seconds = date.getSeconds();
	var dat = year+"-"+month+"-"+day;   //当前日期
	var dat1 = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;   //当前日期时间
	
	if(month < 10){
		month = 0+""+month;
	}
	if(day < 10){
		day = 0+""+day;
	}
	var dat = year+"-"+month+"-"+day;   //当前日期
	var value = $("#time").val();
	time1(dat);

	//标准版日期选择器，
	laydate.render({
	    elem: '#time',	//加在那个文本框中，选中文本框的id
	    max: fundata(),
	    value:dat,
	    done:function(value){
	    	var js = $("#teacher").val();
	    	if(js!=""){
	    		$("#formEdit").data('bootstrapValidator').destroy();	//将验证清空
				$("#formEdit").data('bootstrapValidator',null);
				formValidator();										//重新加载验证
	    	}
		    	$("#kc").empty();
		    	$.ajax({  
		    	//get请求地址  
		    	    url: 'time?time='+value,  
		    	    dataType: "json",  
		    	    success: function (data) {
		    	    	 $('#content').selectpicker('val',['noneSelectedText'])//回到初始状态
		    	    	   $("#content").selectpicker('refresh');//刷新
		    	        for (var i = 0; i < data.length; i++) {  
		    	            $('#kc').append("<option value=" + data[i].id + "> "+data[i].jc +"</option>");  
		    	        }
		    	        // 缺一不可  
		    	        $('#kc').selectpicker('refresh');  
		    	        $('#kc').selectpicker('render');
		    	        if(data.length==0){
		    	             document.getElementById("teacher").value = null;  	
		    				 document.getElementById("jc").value = null;  	//课程执空
		    				 document.getElementById("bj").value = null;  	
		    				 document.getElementById("rs").value = null; 
		    				 var jc = $("#jc").val();
		 	    	    	if(jc==null||jc==""){
		 	    	    		 $("#tj").prop('disabled', true);
		 	    	    		 $("#content").prop('disabled', true);
		 	    	    	}
		    	        }else{
		    	    		$("#tj").prop('disabled', false);
		    	         	$("#content").prop('disabled', false);
			    	        $("#content").empty();
			    			$.ajax({  
			    			    url: 'content?kc='+data[0].id,  
			    			    dataType: "json",  
			    			    success: function (data) {
		    				    	$('#content').append("<option style='display: none;'></option>");
		    				        for (var i = 0; i < data.length; i++) {  
		    				        	$('#content').append("<option value=" + data[i].content + "> "+data[i].content +"</option>");   
		    				        }  
		    				        // 缺一不可  
		    				        $('#content').selectpicker('refresh');  
		    				        $('#content').selectpicker('render');
		    				 	   }  
			    				});
			    			
			    			 $.post("data",{id:data[0].id},function(data){
			    				 document.getElementById("teacher").value = data.teacher; 
			    				 document.getElementById("id").value = data.id;  	
			    				 document.getElementById("jc").value = data.course;  	
			    				 document.getElementById("bj").value = data.classes;  	
			    				 document.getElementById("rs").value = data.ydrs;
			    				 document.getElementById("jc1").value = data.jc;  	
			    				 formValidator();
			    			 });
		    	         }
		    	   	 }  
		    	});
	    	
	    }
	});
});	
	function time1(value){
		$('#content').selectpicker('val',['noneSelectedText'])//回到初始状态
  	    $("#content").selectpicker('refresh');//刷新
		$("#kc").empty();
    	$.ajax({  
    	//get请求地址  
    	    url: 'time?time='+value,  
    	    dataType: "json",  
    	    success: function (data) {
    	    	$("#tj").prop('disabled', false);
    	        for (var i = 0; i < data.length; i++) {  
    	            $('#kc').append("<option value=" + data[i].id + "> "+data[i].jc +"</option>");  
    	        }
    	        // 缺一不可  
    	        $('#kc').selectpicker('refresh');  
    	        $('#kc').selectpicker('render');
    	        if(data.length==0){
    	        	 document.getElementById("content").value = null;  	
    	             document.getElementById("teacher").value = null;  	
    				 document.getElementById("jc").value = null;  	
    				 document.getElementById("bj").value = null;  	
    				 document.getElementById("rs").value = null; 
    				 var jc = $("#jc").val();
 	    	    	if(jc==null||jc==""){				
 	    	    		 $("#tj").prop('disabled', true);
 	    	    	}
    	        }else{
	    	        $("#content").empty();
	    	        if(data[0].id!=null||data[0].id!=""){
	    	        	$.ajax({  
		    			    url: 'content?kc='+data[0].id,  
		    			    dataType: "json",  
		    			    success: function (data) {  
		    				    	$('#content').append("<option style='display: none;'></option>");
		    				        for (var i = 0; i < data.length; i++) {  
		    				        	$('#content').append("<option value=" + data[i].content + "> "+data[i].content +"</option>");   
		    				        }  
		    				        // 缺一不可  
		    				        $('#content').selectpicker('refresh');  
		    				        $('#content').selectpicker('render');
		    				    }  
		    				});
	    	        	
	    	        	 $.post("data",{id:data[0].id},function(data){
		    				 document.getElementById("teacher").value = data.teacher; 
		    				 document.getElementById("id").value = data.id;  	
		    				 document.getElementById("jc").value = data.course;  	
		    				 document.getElementById("bj").value = data.classes;  	
		    				 document.getElementById("rs").value = data.ydrs;
		    				 document.getElementById("jc1").value = data.jc;  	
		    				 formValidator();
		    			 });
	    	        }
    	         }
    	   	 }  
    	});
	}
	
	/* 锁日期键盘 */
	function fundata(){
		var now = new Date();
	    return now.getFullYear()+"-" + (now.getMonth()+1) + "-" + now.getDate();
	}
	
	/* 节次发生变化后 */
	function fun(value){
		$("#formEdit").data('bootstrapValidator').destroy();	//将验证清空
		$("#formEdit").data('bootstrapValidator',null);
		$("#content").empty(); 
		$.ajax({  
		    url: 'content?kc='+value,  
		    dataType: "json",  
		    success: function (data) {
			    	$('#content').append("<option style='display: none;'></option>");
			        for (var i = 0; i < data.length; i++) {  
			        	$('#content').append("<option value=" + data[i].content + "> "+data[i].content +"</option>");   
			        }  
			        // 缺一不可  
			        $('#content').selectpicker('refresh');  
			        $('#content').selectpicker('render');
			    }  
			});
		
		 $.post("data",{id:value},function(data){
			 document.getElementById("teacher").value = data.teacher; 
			 document.getElementById("id").value = data.id;  	
			 document.getElementById("jc").value = data.course;  	
			 document.getElementById("bj").value = data.classes;  	
			 document.getElementById("rs").value = data.ydrs; 
			 document.getElementById("jc1").value = data.jc;  	
			 formValidator();
		 	});
		}
</script>
	<div class="container">
		<form id="formEdit" action="save" class="form-horizontal col-md-11 col-md-offset-3">
		<input id="id" type="hidden" name="id">
			<div class="form-group">
               	<label for="time" class="col-md-1 control-label">日期</label>
                <div class="col-md-4">
					<input type="text" class="form-control" id="time" name="time" onchange="time1(this.value);">  
					<span class="glyphicon glyphicon-calendar form-control-feedback" style="margin-right: 10px;"></span>                  
				</div>
            </div>
			<div class="form-group">
               	<label for="teacher" class="col-md-1 control-label">教师</label> 
                <div class="col-md-4">
					<input type="text" class="form-control" readonly="readonly" id="teacher">
				</div>
            </div>
			
			<div class="form-group">
               	<label for="kc" class="col-md-1 control-label">节次</label>
                <div class="col-md-4">
					<select id="kc"  data-live-search="true" onchange="fun(this.value)">
					</select> 
					<input type="hidden" id="jc1">
				</div>
            </div>
			<div class="form-group">
               	<label for="content" class="col-md-1 control-label">内容</label>
                <div class="col-md-4">
					<select id="content"  data-live-search="true" name="sknr">
						
					</select> 
				</div>
            </div>
			
			<div class="form-group">
               	<label for="jc" class="col-md-1 control-label">课程</label>
                <div class="col-md-4">
					<input type="text"class="form-control" readonly="readonly"id="jc">
				</div>
            </div>
			
			<div class="form-group">
               	<label for="bj" class="col-md-1 control-label">班级</label>
                <div class="col-md-4">
					<input type="text"class="form-control" readonly="readonly" id="bj">
				</div>
            </div>
			
			<div class="form-group">
               	<label for="rs" class="col-md-1 control-label">人数</label>
                <div class="col-md-4">
					<input type="text"class="form-control" readonly="readonly" id="rs" name="sdrs">
				</div>
            </div>
               
			 <div class="form-group">
               	<label for="remarks" class="col-md-1 control-label">授课备注</label>
                   <div class="col-md-4">
                    <input type="text" name="remarks" class="form-control" id="remarks" placeholder="授课备注">
                   </div>
               </div>
               
               <div class="form-group">
               	<label class="col-md-1 control-label"></label>
                   <div class="col-md-4">
                   	<button type="submit" class="btn btn-success" id="tj" style="width:100%;" disabled="disabled"><span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>确认</button>
                   </div>
               </div>
		</form>
	</div>
<script type="text/javascript">
function formValidator() {
	$('#formEdit').bootstrapValidator({
		message : '验证不通过',
		excluded : [':disabled'],//[':disabled', ':hidden', ':not(:visible)']
		feedbackIcons : {
			valid : 'glyphicon glyphicon-ok',
			invalid : 'glyphicon glyphicon-remove',
			validating : 'glyphicon glyphicon-refresh'
		},
		fields : {
			sknr : {
				validators : {
					notEmpty : {
						message : '上课内容不能为空'
					}
				}
			}
		}
	}).on('success.form.bv', function(e) {
		e.preventDefault(); 								//很重要没有它则会提交默认表单，不会做下面的ajax表单提交
		var fd = new FormData($("#formEdit")[0]);
		$.ajax({
			url : "save",
			type : "POST",
			data : fd,
			processData : false, 							// 不处理数据  
			contentType : false, 							// 不设置内容类型
			success : function(result) {
				alert("数据保存成功");
				window.location.reload();
			},
			error : function(result) {
				alert(result);
			}
		});
	});
}
</script>

</section>
</body>
</html>